<!--
 * @Descripttion:
 * @Author: zhangziyu
 * @Date: 2022-11-05 18:00:56
 * @LastEditors: zhangziyu
 * @LastEditTime: 2022-11-17 16:12:15
 * @Introduce: 乡农课堂
-->
<template>
  <div class="content">
    <el-breadcrumb separator="/" class="mb20">
      <el-breadcrumb-item :to="{ path: '/' }"><span class="gray"><i class="el-icon-s-home"></i>首页</span></el-breadcrumb-item>
      <el-breadcrumb-item><span class="green">乡农课堂</span></el-breadcrumb-item>
    </el-breadcrumb>
    <div class="classroom">
      <div class="searchbox">
        <el-input placeholder="请输入内容" v-model="keyword" class="input-with-select">
        <el-select v-model="select" slot="prepend" placeholder="请选择">
          <el-option label="课程" value="1"></el-option>
          <el-option label="专家" value="2"></el-option>
        </el-select>
        <el-button slot="append" class="btn" @click="search">搜索</el-button>
      </el-input>
      </div>
      <h2>{{levelI.label}}</h2>
      <div class="tabs" v-loading="dataListLoading">
        <span class="tips">课程类型：</span>
        <!-- <span class="more">更多<i class="el-icon-arrow-down"></i></span> -->
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane :label="tab.label" :name="tab.value" v-for="(tab,ind) in tabArr" :data-item="JSON.stringify(tab)" :key="ind+'a'">
            <div class="crList" v-if="dataList.length>0">
              <!-- <div class="crItem"  v-for="(item,index) in ind%2==0?dataJson1:dataJson2" :key="index"> -->
              <div class="crItem"  v-for="(item,index) in dataList" :key="index" @click="gotoview">
                <div class="imgbox">
                  <img :src="item.headUrl" alt="" srcset="" class="crImg"/>
                  <span class="istop" v-if="item.moveTop==0">置顶</span>
                  <span class="time">{{item.videoDuration}}</span>
                </div>
                <div class="crCon">
                  <h3>{{item.videoTitle}}</h3>
                  <el-row>
                    <el-col :span="12" class="col1">讲师：{{item.authorName}}</el-col>
                    <el-col :span="12" class="col2">{{item.videoPlayCount}}次观看</el-col>
                  </el-row>
                  <el-row>
                    <el-tag size="medium" class="tag"  effect="dark" type="success" v-for="tag in item.classifyNames.split(',')" :key="tag">{{tag}}</el-tag>
                  </el-row>
                </div>
              </div>
            </div>
            <div class="noData" v-else>
              <span>暂无数据</span>
            </div>
             <div class="pagination">
              <el-pagination
                class="paging"
                :current-page="page"
                :total="total"
                :page-size='limit'
                layout="total,prev, pager, next,jumper"
                @size-change="pageSizeChangeHandle"
                @current-change="pageCurrentChangeHandle">
              </el-pagination>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </div>
</template>

<script>
// import { dataJson1, dataJson2, tabArr } from './data'
import mixinViewModule from '@/mixins/view-module'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      tabArr: [],
      levelII: {},
      levelI: '',
      mixinViewModuleOptions: {
        getDataListURL: '/web/video/allVideoPage',
        getDataListIsPage: true
      },
      keyword: '',
      select: '1',
      activeName: ''

    }
  },
  mounted () {
    this.levelI = JSON.parse(this.$route.query.value)
    this.levelII = this.$route.query.id
    if (this.levelII) {
      this.dataForm.typeCode = this.levelII
    }
    window.scrollTo(0, 0)
    this.getDataList()
    this.getSecondTypesByFirstCode()
  },
  methods: {
    // 根据一级分类获取二级分类结构数据
    getSecondTypesByFirstCode () {
      this.$http.get(`/web/video/getSecondTypesByFirstCode/${this.levelI.value}`).then(({ data: res }) => {
        if (res.code !== 0) {
          this.$message.error(res.msg)
          return false
        }
        this.tabArr = res.data
        this.tabArr.unshift({ label: '全部', value: this.levelI.value })
        this.activeName = this.levelII
      }).catch(() => {})
    },
    handleClick (el) {
      let node = JSON.parse(el.$el.dataset.item)
      this.dataForm.typeCode = node.value
      this.getDataList()
    },
    search () {
      this.$router.push({
        name: 'searchshow',
        query: {
          word: this.keyword
        }
      })
    },
    gotoview () {
      this.$router.push({
        name: 'classroomview'
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.content{
  width: 1200px;
  margin: 0 auto;
  padding: 20px 0;
  .mb20{margin-bottom: 20px;}
  .gray{color: #C2C6CC;}
  .green{
    color:#2b970d;
  }
}
.classroom{
  .searchbox{
    text-align: center;
    width: 600px;
    margin: 30px auto;
    /deep/ .el-input-group__prepend{width: 80px;background-color: inherit;}
    .btn{background-color: #26840C;color: #fff;}
  }
  .tabs{
    position: relative;
    /deep/.el-tabs__nav-wrap::after{
      height:0;
    }
    /deep/ .el-tabs__item{
      padding:0 10px !important;
      height: 34px;
      line-height: 34px;
      text-align: center;
      margin-right: 10px;
    }
    /deep/ .el-tabs__item:hover{color: #26840C;}
    /deep/ .el-tabs__item.is-active{
      color:#26840C;
      border-radius: 5px;
      background-color: #26840C25;
    }
    /deep/ .el-tabs__active-bar{
      height: 0;
      background-color: inherit;
    }
    /deep/ .el-tabs__header{
      margin-left: 80px;
      width: calc(100% - 100px);
    }
    .tips{
      position: absolute;
      left: 0;
      top: 10px;
    }
    .more{
      position: absolute;
      right: 0;
      top: 10px;
      color: #999;
      font-size: 14px;
      cursor: pointer;
    }
    .crList{overflow: hidden;}
    .noData{
        line-height: 300px;
        text-align: center;
        span{
          color:#6e6e6e
        }
    }
    .crItem{
      width: 224px;
      cursor: pointer;
      margin: 0 20px 20px 0;
      float: left;
      .imgbox{
        width: 100%;
        height: 168px;
        display:block;
        position: relative;
        .crImg{
          width: 100%;
          height: 100%;
          display:block;
        }
        .istop{
          width: 70px;
          height: 30px;
          color: #fff;
          text-align: center;
          line-height: 30px;
          background-color: #20a473;
          border-radius: 4px;
          position: absolute;
          top:0;
          left: 0;
        }
        .time{
          position: absolute;
          bottom: 4px;
          left: 10px;
          color: #fff;
          border-radius: 3px;
          background-color: #00000070;
          padding: 4px 5px;
          line-height: 1;
          font-size: 12px;
        }
      }
      .crCon{
        padding: 10px;
        border: 1px solid #E4E7ED;
        h3{
          height: 50px;
          font-size: 16px;
          color: #333333;
          margin: 5px 0;
        }
        .col1{
          font-size: 12px;
          margin-bottom: 10px;
        }
        .col2{
          font-size: 12px;
          color: #999999;
          text-align: right;
          margin-bottom: 10px;
        }
        .tag{
          background-color: #26840C;
          border-color: #26840C;
          height: 25px;
          line-height: 25px;
          padding: 0 6px;
          margin-right: 5px;
        }
      }
      &:nth-child(5n){
        margin-right: 0;
      }
    }
    .pagination{
      width: 100%;
      text-align: center;
      margin: 20px 0;

      .paging /deep/ .el-pager li{
        background-color: inherit;
        border: 1px solid #ddd;
        margin: 0 4px;
        color: #333333;
      }
      /deep/ .el-pagination .btn-next,/deep/ .el-pagination .btn-prev{
        border: 1px solid #ddd;
        margin: 0 4px;
      }
      .paging /deep/ .el-pager li.active{
        border-color: #2b970d;
        color: #2b970d;
      }
    }
  }

}
</style>
